package com.df.blueben.AiClient;


import com.df.blueben.model.entity.Tags;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class TagsSelectAi {

    private static final String SYSTEM_PROMPT = "你是一个数据分析师，用户会输入的标题和内容还有标签列表，" +
            "你需要根据用户输入的标题和内容从用户输入的标签列表中选择一个最匹配用户输入的标题和内容的标签，只能从给定的标签列表中选择";
    private final ChatClient chatClient;

    TagsSelectAi(ChatModel dashScopeChatModel){
        chatClient = ChatClient.builder(dashScopeChatModel)
                .defaultSystem(SYSTEM_PROMPT)
                .build();
    }

    public Tags getTags(String title, String content, List<Tags> tags){
        String format = String.format("标题：%s\n内容：%s\n标签列表：%s", title, content, tags);
        return chatClient.prompt().user(format).call().entity(Tags.class);
    }

}
